"""Run Phase 3 refactoring tests and capture output."""
import os
import subprocess
import sys

# Run pytest with proper PYTHONPATH
env = os.environ.copy()
env["PYTHONPATH"] = "backend"

result = subprocess.run(
    [sys.executable, "-m", "pytest", "tests/test_refactoring_phase3.py", "-v", "--tb=short"],
    capture_output=True,
    text=True,
    env=env
)

print(result.stdout)
if result.stderr:
    print("STDERR:", result.stderr)
print(f"\nExit code: {result.returncode}")
